import axios from 'axios'

import { BASE_RUL, TIME_OUT } from '@/services/request/config'

// 请求类
class HYRequest {

  constructor(baseURl, timeout){

    this.instance = axios.create({
      baseURL: baseURl,
      timeout: timeout
    })
    // 请求拦截
    this.instance.interceptors.request.use((config) => {
      return config;
    })
    // 响应拦截
    this.instance.interceptors.response.use((res) => {
      return res.data;
    },err=>{
      return err
    })

  }

  request(config){
    return this.instance.request(config);
  }
  get(config){
    console.log('config',config)
    return this.request({...config,method:'get'})
  }
  post(config){
    return this.request({...config,method:'post'})
  }
}

// 导出类的对象
const hyRequest = new HYRequest(BASE_RUL, TIME_OUT);
export default hyRequest
